home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / include / RCS / hash.h,v < prev    next >
Encoding:
Text File  |  1991-07-27  |  4.6 KB  |  198 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     89.06.23.11.29.46;  author rab;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     88.06.29.14.57.27;  author ouster;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.06.21.09.36.52;  author ouster;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 1.3
  30. log
  31. @*** empty log message ***
  32. @
  33. text
  34. @/* hash.h --
  35.  *
  36.  *     This file contains definitions used by the hash module,
  37.  *     which maintains hash tables.
  38.  *
  39.  * Copyright 1986, 1988 Regents of the University of California
  40.  * Permission to use, copy, modify, and distribute this
  41.  * software and its documentation for any purpose and without
  42.  * fee is hereby granted, provided that the above copyright
  43.  * notice appear in all copies.  The University of California
  44.  * makes no representations about the suitability of this
  45.  * software for any purpose.  It is provided "as is" without
  46.  * express or implied warranty.
  47.  *
  48.  * $Header: /sprite/src/lib/include/RCS/hash.h,v 1.2 88/06/29 14:57:27 ouster Exp Locker: rab $ SPRITE (Berkeley)
  49.  */
  50.  
  51.  
  52. #ifndef    _HASH
  53. #define    _HASH
  54.  
  55. #ifndef _LIST
  56. #include <list.h>
  57. #endif
  58. #ifndef _SPRITE
  59. #include <sprite.h>
  60. #endif
  61.  
  62. /* 
  63.  * The following defines one entry in the hash table.
  64.  */
  65.  
  66. typedef struct Hash_Entry {
  67.     List_Links          links;        /* Used to link together all the
  68.                          * entries associated with the same
  69.                      * bucket. */
  70.     ClientData          clientData;    /* Arbitrary piece of data associated
  71.                          * with key. */
  72.     union {
  73.     Address     ptr;            /* One-word key value to identify
  74.                      * entry. */
  75.     int words[1];            /* N-word key value.  Note: the actual
  76.                      * size may be longer if necessary to
  77.                      * hold the entire key. */
  78.     char      name[4];        /* Text name of this entry.  Note: the
  79.                      * actual size may be longer if
  80.                      * necessary to hold the whole string.
  81.                      * This MUST be the last entry in the
  82.                      * structure!!! */
  83.     } key;
  84. } Hash_Entry;
  85.  
  86. /* 
  87.  * A hash table consists of an array of pointers to hash
  88.  * lists.  Tables can be organized in either of three ways, depending
  89.  * on the type of comparison keys:
  90.  *
  91.  *    Strings:      these are NULL-terminated; their address
  92.  *              is passed to HashFind as a (char *).
  93.  *    Single-word keys: these may be anything, but must be passed
  94.  *              to Hash_Find as an Address.
  95.  *    Multi-word keys:  these may also be anything; their address
  96.  *              is passed to HashFind as an Address.
  97.  *
  98.  *    Single-word keys are fastest, but most restrictive.
  99.  */
  100.  
  101. #define HASH_STRING_KEYS    0
  102. #define HASH_ONE_WORD_KEYS    1
  103.  
  104. typedef struct Hash_Table {
  105.     List_Links     *bucketPtr;    /* Pointer to array of List_Links, one
  106.                      * for each bucket in the table. */
  107.     int     size;        /* Actual size of array. */
  108.     int     numEntries;    /* Number of entries in the table. */
  109.     int     downShift;    /* Shift count, used in hashing function. */
  110.     int     mask;        /* Used to select bits for hashing. */
  111.     int     keyType;    /* Type of keys used in table:
  112.                      * HASH_STRING_KEYS, HASH_ONE-WORD_KEYS,
  113.                  * or >1 menas keyType gives number of words
  114.                  * in keys.
  115.                  */
  116. } Hash_Table;
  117.  
  118. /* 
  119.  * The following structure is used by the searching routines
  120.  * to record where we are in the search.
  121.  */
  122.  
  123. typedef struct Hash_Search {
  124.     Hash_Table  *tablePtr;    /* Table being searched. */
  125.     int     nextIndex;    /* Next bucket to check (after current). */
  126.     Hash_Entry     *hashEntryPtr;    /* Next entry to check in current bucket. */
  127.     List_Links    *hashList;    /* Hash chain currently being checked. */
  128. } Hash_Search;
  129.  
  130. /*
  131.  * Macros.
  132.  */
  133.  
  134. /*
  135.  * ClientData Hash_GetValue(h) 
  136.  *     Hash_Entry *h; 
  137.  */
  138.  
  139. #define Hash_GetValue(h) ((h)->clientData)
  140.  
  141. /* 
  142.  * Hash_SetValue(h, val); 
  143.  *     HashEntry *h; 
  144.  *     char *val; 
  145.  */
  146.  
  147. #define Hash_SetValue(h, val) ((h)->clientData = (ClientData) (val))
  148.  
  149. /* 
  150.  * Hash_Size(n) returns the number of words in an object of n bytes 
  151.  */
  152.  
  153. #define    Hash_Size(n)    (((n) + sizeof (int) - 1) / sizeof (int))
  154.  
  155. /*
  156.  * The following procedure declarations and macros
  157.  * are the only things that should be needed outside
  158.  * the implementation code.
  159.  */
  160.  
  161. extern Hash_Entry *    Hash_CreateEntry();
  162. extern void        Hash_DeleteTable();
  163. extern void        Hash_DeleteEntry();
  164. extern void        Hash_DeleteTable();
  165. extern Hash_Entry *    Hash_EnumFirst();
  166. extern Hash_Entry *    Hash_EnumNext();
  167. extern Hash_Entry *    Hash_FindEntry();
  168. extern void        Hash_InitTable();
  169. extern void        Hash_PrintStats();
  170.  
  171. #endif /* _HASH */
  172. @
  173.  
  174.  
  175. 1.2
  176. log
  177. @Add ifdefs so that file can't be processed twice.
  178. @
  179. text
  180. @d15 1
  181. a15 1
  182.  * $Header: hash.h,v 1.1 88/06/21 09:36:52 ouster Exp $ SPRITE (Berkeley)
  183. d138 1
  184. a138 1
  185. #endif _HASH
  186. @
  187.  
  188.  
  189. 1.1
  190. log
  191. @Initial revision
  192. @
  193. text
  194. @d15 1
  195. a15 1
  196.  * $Header: hash.h,v 1.1 88/06/20 09:30:26 ouster Exp $ SPRITE (Berkeley)
  197. @
  198.